package com.sifeng.test;

import com.sifeng.enums.FileTypeEnum;
import com.sifeng.utils.MyUtils;
import com.sifeng.utils.StringUtils;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributeView;
import java.nio.file.attribute.BasicFileAttributes;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * Created by yang_gsh on 2018/10/7.
 * 将文件按日期进行分类，导入到文件日期分类的文件夹中
 */
public class CopyFileToDestinationDirectory {

	public static void executeCopyFile(String fileStr, String dirPath, String desPath) {
		List<String> fileList = MyUtils.readDirectory(dirPath, FileTypeEnum.FILE);

		for (String s : fileList) {
			String filePath = dirPath + "\\" + s;
			if (!s.contains(fileStr)) {
				continue;
			} else {
				//System.out.println(createTime_tmp);
				try {
					FileUtils.copyFileToDirectory(new File(filePath), new File(desPath),true);
				} catch (IOException e) {
					e.printStackTrace();
					continue;
				}
			}
		}
	}

	public static void main(String[] args) {
		String fileStr = "功能点评估表";
		for (int i = 1; i <= 12; i++) {
			String dirPath = "E:\\hisun\\开发三部\\功能点评估表\\2018" + StringUtils.leftPad(String.valueOf(i),2,"0");
			String desPath = "E:\\hisun\\开发三部\\tmp\\2018" + StringUtils.leftPad(String.valueOf(i),2,"0");
			CopyFileToDestinationDirectory.executeCopyFile(fileStr, dirPath, desPath);
		}
	}
}